package com.example.myapplication.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.example.myapplication.ImgInfo.GridInfo;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

public class MyServiceAdapter extends BaseAdapter {

    private List<GridInfo.Grid> gridList = new ArrayList<GridInfo.Grid>();
    private Context context;
    private RequestQueue queue;

    public MyServiceAdapter(List<GridInfo.Grid> gridList, Context ctx, RequestQueue queue) {
        this.gridList = gridList;
        this.context = ctx;
        this.queue = queue;
    }

    @Override
    public int getCount() {
        return gridList.size();
    }

    @Override
    public Object getItem(int i) {
        return gridList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View v = LayoutInflater.from(context).inflate(R.layout.gird_service_item, null);
        ImageView img = v.findViewById(R.id.gird_item_img);
        TextView text = v.findViewById(R.id.gird_item_name);

        GridInfo.Grid grid = gridList.get(i);
        text.setText(grid.getServiceName());

        String imgUrl = Config.URL + grid.getImgUrl();
        if (grid.getServiceName().equals("全部服务")) {

        } else {
            ImageUtils.Loadimg(img, imgUrl, queue);
        }

        return v;
    }
}
